<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Http\Response;

class BusinessException extends Exception
{
    /**
     * 业务异常代码
     *
     * @var int
     */
    protected $code = Response::HTTP_BAD_REQUEST;

    /**
     * 业务异常消息
     *
     * @var string
     */
    protected $message = '业务逻辑错误';

    /**
     * 业务异常数据
     *
     * @var array
     */
    protected $data = [];

    /**
     * 创建业务异常实例
     *
     * @param  string  $message
     * @param  int  $code
     * @param  array  $data
     * @return void
     */
    public function __construct($message = null, $code = null, $data = [])
    {
        if ($message !== null) {
            $this->message = $message;
        }

        if ($code !== null) {
            $this->code = $code;
        }

        $this->data = $data;

        parent::__construct($this->message, $this->code);
    }

    /**
     * 获取业务异常数据
     *
     * @return array
     */
    public function getData()
    {
        return $this->data;
    }
} 